import request from '@/utils/request'

const baseUri = '/user'

const userService = {
  //登陆
  login: (userLoginDto) => {
    return request({
      url: `${baseUri}/login`,
      method: 'post',
      data: userLoginDto
    })
  },
  //退出登陆
  logout: () => {
    return request({
      url: `${baseUri}/logout`,
      method: 'post'
    })
  },
  //获取登录信息
  getInfo: (token) => {
    return request({
      url: `${baseUri}/info`,
      method: 'get',
      params: { token }
    })
  },
  //修改用户的角色
  updateUserRole: (updateUserRoleDto) => {
    return request({
      url: `${baseUri}/updateUserRole`,
      method: 'post',
      data: updateUserRoleDto
    })
  },
  list: (searchMap) => {
    return request({
      url: `${baseUri}/list`,
      method: 'post',
      data: searchMap
    })
  },
  find: (id) => {
    return request({
      url: `${baseUri}/find`,
      method: 'get',
      params: { id }
    })
  },
  findAll: () => {
    return request({
      url: `${baseUri}/findAll`,
      method: 'get'
    })
  },
  update(id,user) {

    //判断是否有ID，没有就是新增
    if(id===null || id===''){
      return this.add(user)
    }
    return request({
      url: `${baseUri}/update`,
      method: 'post',
      data: user // 将部门对象作为请求体传递
    });
  },
  
  add(user) {
    return request({
      url: `${baseUri}/add`,
      method: 'post',
      data: user
    });
  },
  remove: (id) => {
    return request({
      url: `${baseUri}/delete`,
      method: 'get',
      params: { id }
    })
  },
  batchRemove: (batchDeleteDto) => {
    return request({
      url: `${baseUri}/batchRemove`,
      method: 'post',
      data: batchDeleteDto
    })
  }
}

export default userService
